package obecto.utility
{
	import flash.utils.Dictionary;
	
	public class ObjectPropertiesProxy
	{
		public var preInitializationTarget : Object;
		
		private var _target : Object;
		public function set target(value : Object) : void
		{
			_target = value;
			applyProperties();
		}
		public function get target() : Object
		{
			return _target;
		}
		
		public var properties : Dictionary;
		
		public function ObjectPropertiesProxy(taget : Object = null)
		{
			_target = taget;
			properties = new Dictionary();
		}
		
		public function setProperty(key : Object, value : *) : void
		{
			if (_target)
			{
				_target[key] = value;				
			}
			
			properties[key] = value;
		}
		
		public function getProperty(key : Object, atrerativeValue : * = undefined) : *
		{
			if(properties[key] != undefined)
			{
				return properties[key];
			}
			
			return atrerativeValue;
		}
		
		private function applyProperties() : void
		{
			for (var key : Object in properties)
			{
				_target[key] = properties[key];
			}
		}
	}
}